//
//  ICMCustomerInfoView.m
//  ICrEAM
//
//  Created by Cty on 2016/11/01.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMCustomerInfoView.h"
#import "ICMCustomInfoCell.h"
#import "RelectiveAppointMentModel.h"
@implementation ICMCustomerInfoView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
//+(instancetype)creatCustomerInfoViewWithFrame:(CGRect)frame andModel:(ICMCustomerInfoModel *)model{
//    return [[ICMCustomerInfoView alloc]initWithFrame:frame andModel:model];
//
//}
-(void)setupinitData:(ICMCustomerInfoModel *)model{
    self.cusomerInfo = model;
    
    self.licenseNum.text = self.cusomerInfo.licenseNum;
    
    self.vinNum.text = self.cusomerInfo.vinNum;
    
    self.customerNum.text = self.cusomerInfo.customerNum;
    
    self.phoneNumer.text = self.cusomerInfo.phoneNumer;
    
    self.isvip.text = self.cusomerInfo.VipCount;
    
    self.hasLastSuggestion.text =self.cusomerInfo.hasLastSuggestion?@"有":@"无";
    if (!self.cusomerInfo.hasLastSuggestion){
        self.lastSuggestionDetail.enabled = NO;
        self.firstLabel.hidden = YES;
        self.firstLine.hidden = YES;
    }
    
//    if (!model.isTechActiv) {
//        self.techImage.image=[UIImage imageNamed:@"white_hoshi"];
//    }
    self.techImage.hidden=!model.isTechActiv;
    self.hasReservedData.text =self.cusomerInfo.hasReservedData?@"有":@"无";;
    if (!self.cusomerInfo.hasReservedData){
        self.reservedDataDetail.enabled = NO;
        self.secondLabel.hidden = YES;
        self.secondLine.hidden= YES;
    }
    
    self.hasRecall.text =
    self.cusomerInfo.hasRecall?@"有":@"无";;
    if (!model.hasRecall) {
        self.backLabel.textColor=[UIColor whiteColor];
    }
    else
    {
        self.backLabel.textColor=[UIColor redColor];
    }
    if (!model.hasRecall) {
        self.lineThreeView.hidden=YES;
        self.returnBtn.hidden=YES;
        self.ThressDetailB.hidden=YES;
    }
    self.hasService.text =
    self.cusomerInfo.hasService?@"有":@"无";;
    if (!self.cusomerInfo.hasService){
        self.serviceDetail.enabled = NO;
        self.thirdLabel.hidden = YES;
        self.thirdLine.hidden = YES;
    }

    
    self.isThreeGuarantees.text =
    self.cusomerInfo.isThreeGuarantees?@" 是":@"否";;

    if (self.cusomerInfo.TT_REPAIR_ORDER.count) {
        [self.appintTableView reloadData];
    }

}
//tag 100开始
- (IBAction)clickButton:(UIButton *)sender {
    NSInteger index=sender.tag-100;
    if ([self.delegate respondsToSelector:@selector(clickDetailBtnAtIndex:)]) {
        [self.delegate clickDetailBtnAtIndex:index];
    }
}

//- (instancetype)initWithCoder:(NSCoder *)aDecoder
//{
//    if(self = [super initWithCoder:aDecoder])
//    {
//        
//    }
//    return self;
//}

- (void)awakeFromNib
{
    [super awakeFromNib];
    self.linkBookingNoFlagImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapLinkBookingNoGr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(linkBookingNo:)];
    [self.linkBookingNoFlagImageView addGestureRecognizer:tapLinkBookingNoGr];
    if (![ICrEAMTool isVW]) {
        self.bgview.backgroundColor=KSKBgColor;
        self.appintTableView.backgroundColor=KSKBgColor;
    }
    self.appintTableView.delegate = self;
    self.appintTableView.dataSource = self;
    self.appintTableView.contentInset = UIEdgeInsetsMake(0, 0, 63, 0);
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.cusomerInfo.TT_REPAIR_ORDER.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ICMCustomInfoCell *cell=[ICMCustomInfoCell createICMCustomInfoCell];
    cell.indexPath=indexPath;
    RelectiveAppointMentModel *model=self.cusomerInfo.TT_REPAIR_ORDER[indexPath.row];
    if(!IsStrEmpty(self.cusomerInfo.bookingNoStr) && [model.BOOKING_ORDER_NO isEqualToString:self.cusomerInfo.bookingNoStr])
    {
        model.isSelect = YES;
    }
    else
    {
        model.isSelect = NO;
    }
    cell.model=model;
    if (!IsStrEmpty(self.cusomerInfo.bookingNoStr)) {
        cell.selectBtn.enabled=NO;
        if([model.BOOKING_ORDER_NO isEqualToString:self.cusomerInfo.bookingNoStr])
        {
            cell.hidden = NO;
        }
        else
        {
            cell.hidden = YES;
        }
    }
    cell.selectedBlock=^(NSInteger index,BOOL isSelected){
        NSString *appointNo;
        for (int i=0; i<self.cusomerInfo.TT_REPAIR_ORDER.count; i++) {
            RelectiveAppointMentModel *flushmodel=self.cusomerInfo.TT_REPAIR_ORDER[i];
            if (index==i) {
                appointNo=flushmodel.BOOKING_ORDER_NO;
                flushmodel.isSelect=isSelected;
            }else{
                flushmodel.isSelect=NO;
            }
        }
        [self.appintTableView reloadData];
        if (!isSelected) {
            return ;
        }
        if([self.delegate respondsToSelector:@selector(linkBookingNo:)])
        {
            [self.delegate linkBookingNo:appointNo];
        }
    };
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{



    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 90;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}

@end
